// Pict.cpp : implementation file
//

#include "stdafx.h"
#include "ASUI.h"
#include "ASUIDlg.h"
#include "Pict.h"
#include "MapGraph.h"
#include "INetworkGraph.h"
#include "IReadingInformation.h"
#include "DummyReadingInformation.h"
#include "ITime.h"
#include "Time.h"
#include "IReading.h"
#include <string>
#include <list>
#include <set>
#include <memory>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPict

CPict::CPict()
{
	nodeId = -1;
	hasChanged = true;
}

CPict::~CPict()
{
}


BEGIN_MESSAGE_MAP(CPict, CEdit)
	//{{AFX_MSG_MAP(CPict)
	ON_WM_PAINT()
	 ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
   
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_RBUTTONDBLCLK()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPict message handlers

void CPict::Clear()
{
	CDC *pDC = GetDC();
 
	
	CRect rect;
	GetClientRect(rect);
	CBrush brush;
	// repaint the window with solid white background
	brush.CreateSolidBrush(RGB(255,255,255));
	pDC->FillRect(rect,&brush);

}
void CPict::OnPaint() 
{
	CPaintDC dc(this);
		Clear();
	if(hasChanged)
	{
		Clear();	
		G.createNewGraph(ids.size(),true);
		G.setIds(ids);		
		hasChanged = false;
	}
							
	
	G.draw(&dc);
	
}


void CPict::setNodeIds(std::set<int> nodes)
{
	if (ids != nodes)
	{
		ids = nodes;
		hasChanged = true;
	}
}
void CPict::OnLButtonDown(UINT nFlags, CPoint point)
{
}


void CPict::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	
}


void CPict::OnRButtonDblClk(UINT nFlags, CPoint point)
{
	
}

void CPict::addEdge(int a,int b)
{
	G.addEdge(a,b);
}

void CPict::OnMouseMove(UINT nFlags, CPoint point){
	SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
    TRACKMOUSEEVENT tme;
    tme.cbSize = sizeof(tme);
    tme.hwndTrack = m_hWnd;
    tme.dwFlags = TME_LEAVE|TME_HOVER;
    tme.dwHoverTime = 1000;
    TrackMouseEvent(&tme);
	nodeId = G.getId(point);
}
LRESULT CPict::OnMouseHover(WPARAM wparam, LPARAM lparam) {
    CDC* pDC = GetWindowDC();
    CRect rect;
    GetWindowRect(&rect);
    /*rect.OffsetRect( -rect.left, -rect.top);
    CBrush brush( RGB(0, 0, 255));
    pDC->FrameRect( &rect, &brush)*/;
    ReleaseDC(pDC);
    return true;
}
int CPict::getId()
{
	return nodeId;
}